package org.example.admin.controller;

import org.example.admin.service.LoginService;
import org.example.admin.dto.LoginDto;
import org.example.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/sys/backend")
public class LoginController {

    @Autowired
    private LoginService loginService;

    // 登录
    @PostMapping("/login")
    public R<String> login(@Validated @RequestBody LoginDto loginDto){
        return loginService.login(loginDto);
    }

    // 刷新token
    @GetMapping("/refresh")
    public R<String> refreshToken(){
        return R.ok(loginService.refreshToken());
    }

    // 登录用户信息
    @GetMapping("/userInfo")
    public R<Map<String, Object>> getUserInfo(){
        return R.ok(loginService.getUserInfo());
    }

}